/******************************************************************************
 * libusernet.h
 * 
 * Public interface for the user-space TCP/IP stack.
 * 
 * Copyright (c) 1999-2000, K A Fraser
 * 
 * $Id: libusernet.h,v 1.1.1.1 2003/01/14 01:02:58 root Exp $
 */

#include <sys/poll.h>
#ifndef INFTIM
#define INFTIM -1
#endif
#include <fcntl.h>

#include "defines.h"
/* This message not defined by Linux */
#undef MSG_WAITALL
#define MSG_WAITALL 0x100

/* The following functions may be implemented here: */

// void init_aggregate(void); 

void user_init(void);
void user_kill(void);
int user_accept     (int s,       void *addr, int *addrlen);
int user_bind       (int s, const void *addr, int  addrlen);
int user_connect    (int s,       void *addr, int  addrlen);
int user_getpeername(int s,       void *addr, int *addrlen);
int user_getsockname(int s,       void *addr, int *addrlen);
int user_getsockopt (int         s,
		     int         level,
		     int         optname,
		     void       *optval,
		     int        *optlen);
int user_setsockopt (int         s,
		     int         level,
		     int         optname,
		     void       *optval,
		     int         optlen);
int user_listen     (int s, int backlog);
int user_recv       (int s, void *buf, int len, int flags);
int user_send       (int s, void *msg, int len, int flags);
int user_shutdown   (int s, int how);
int user_socket     (int af, int type, int protocol);
int user_socketpair (int af, int type, int protocol, int sv[2]);
ssize_t user_read   (int s, void       *buf, size_t nbyte);
ssize_t user_write  (int s, const void *buf, size_t nbyte);
#include <sys/uio.h>
int user_writev(int fd, const struct iovec *vector, int count);
int user_close      (int s);
int user_fcntl      (int fd, int cmd, int arg);
#include <sys/poll.h>
int user_poll       (struct pollfd *fdarray, unsigned long nfds, int timeout);
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
int user_clean(int);


/******************************************************************************
 * Remove nasty blocking stdio...
 */
#include <unistd.h>

#ifdef USE_PTH
#include <pth.h>
#endif

/*Fake out a pthread interface for users */

#ifndef USE_PTH

#define pth_mutex_acquire(a,b,c) ((void) 0)
#define pth_mutex_release(a,b,c) ((void) 0)

#define pthread_create(__thr, __attr, __start, __arg) ((void)0)
#define pthread_cancel(__t) ((void)0)
#define pthread_join(__t, __r) ((void)0)
#define pthread_setcanceltype(__t, __o) ((void)0)
#define sched_yield() ((void)0)
#define PTHREAD_MUTEX_INITIALIZER PTH_MUTEX_INIT
#define pthread_mutex_init(__x, __t) ((void)0)

// printf("\nset pthread lock to NULL"); 

#define pthread_mutex_lock(__x) ((void)0)
#define pthread_mutex_unlock(__x) ((void)0)
#define pthread_mutex_destroy(__x) ((void)0)

#define PTHREAD_COND_INITIALIZER PTH_COND_INIT
#define pthread_cond_init(__x, __t) ((void)0)
#define pthread_cond_wait(__c, __m) ((void)0)
#define pthread_cond_signal(__c) ((void)0)
#define pthread_cond_broadcast(__c) ((void)0)
#define pthread_cond_destroy(__x) ((void)0)
#endif 

/* XXX KAF -- test vars */
#define NUM_BUCKETS 500
extern unsigned int histogram[NUM_BUCKETS];
